namespace  MyWebApi.Repository;
using Microsoft.EntityFrameworkCore;
using MyWebApi.Domian;
public class EfRepository<T> : IRepository<T> where T : class
{
    private readonly SudentDbContext _db;
    private DbSet<T> _tb;
    public EfRepository(SudentDbContext db)
    {
        _db = db;
        _tb = db.set<T>();
    }
    public async Task<List<T>> GetAllAsync()
    {
        return await _tb.ToListAsync();
    }
    public async Task<T>? GetoneAsync(int id)
    {
        var obj = await _tb.FindAsync(id);
        if (obj == null)
        {
            return null;
        }
        return obj;
    }
    public async Task<T> CreateAsync(T entity)
    {
        var obj = await _tb.AddAsync(entity);
        await _db.SavechangeAsync();
        return obj.Entity;
      }
    public async Task<T> CreateAsync(T entity)
    {
        var obj = await _tb.AddAsync(entity);
        await _db.SavechangeAsync();
        return obj.Entity;
      }
    public async Task<T> UpdateAsync(T entity)
    {
        var obj = await _tb.update(entity);
        await _db.SavechangeAsync();
        return obj.Entity;
      }
    public async Task<T> DeleteAsync(T entity)
    {
        var obj = await _tb.update(entity);
        await _db.SavechangeAsync();
        return obj.Entity;
      }
}
   
